
"""
    1、生成唯一文件名
    2、当前时间
"""


import uuid
import hashlib
import datetime
import time


def random():
    """
    生成唯一文件名
    :return:
    """
    # 获取uuid的随机数
    uuid_val = uuid.uuid4()
    # 获取uuid的随机数字符串并转为utf-8格式
    uuid_str = str(uuid_val).encode('utf-8')
    # 获取md5实例
    md5 = hashlib.md5()
    # 拿取uuid的md5摘要
    md5.update(uuid_str)
    # 返回固定长度的字符串
    return md5.hexdigest()


def now_data():
    """
    当前时间
    :return:
    """
    data_time = datetime.datetime.now()
    time_mk = time.mktime(data_time.timetuple())
    times = datetime.datetime.fromtimestamp(time_mk)
    return times
